package com.unmarshaller.propertiesunmarshaller.transformer;

import java.lang.reflect.Field;

import javax.xml.crypto.dsig.TransformException;

import com.unmarshaller.propertiesunmarshaller.ITransformer;
/**
 * boolean类型转换赋值
 * @author hongxiao.z
 * @date	2013-10-21
 */
public class BooleanTransformer implements ITransformer {

	@Override
	public void transformer(Field field, String value) throws TransformException 
	{
		try
		{
			if(value.equalsIgnoreCase("true") || value.equals("1"))
			{
				field.set(null, true);
				return;
			}
			else if(value.equalsIgnoreCase("false") || value.equals("0"))
			{
				field.set(null, false);
				return;
			}
		}
		catch(Exception e)
		{
			throw new TransformException("value:" + value + " invalid, is not transformer --- " + field.getType().getSimpleName() + " to " + field.getName());
		}
		
		throw new TransformException("value:" + value + " invalid, is not transformer --- " + field.getType().getSimpleName() + " to " + field.getName());
	}

}
